#!/usr/bin/env bash

#获取master ip 也就是第一个节点的ip
master_ip=`head -1 /tmp/hosts |awk '{print $1}'`

#然后登陆该节点查看是否已经有当前节点了 如果有则退出安装
ssh $master_ip "kubectl get nodes|grep -q `hostname`"

if [ $? -eq 0 ];then
    exit 0;
fi

CERT_KEY=`ssh $master_ip "kubeadm init phase upload-certs --upload-certs|tail -1"`

join_str=`ssh $master_ip kubeadm token create --print-join-command`

$(echo $join_str " --control-plane --certificate-key $CERT_KEY --v=5")


mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config


kubectl taint nodes `hostname` node-role.kubernetes.io/master:NoSchedule- 2>/dev/null
kubectl taint nodes `hostname` node.kubernetes.io/not-ready:NoSchedule- 2>/dev/null